package com.holy.sh.couviewholy.myview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;

import static org.xmlpull.v1.XmlPullParser.TEXT;

/**
 * Holy Email :victorhhl@163.com
 * Create by Holy on ${data}
 * Description :
 */
public class DrawLineView extends View {
    private Paint mPaint;
    private Canvas mCanvas;

    public DrawLineView(Context context) {
        super(context);
        initPAC();
    }

    public DrawLineView(Context context,  AttributeSet attrs) {
        super(context, attrs);
        initPAC();
    }

    private void initPAC() {
        mPaint=new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setStrokeWidth(3);
        //mPaint.setShadowLayer(10,15,15,Color.GRAY);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int code=6;
        RectF rectF=new RectF();
        switch (code) {
            case 0:
                canvas.drawRGB(255,233,200);
                canvas.drawCircle(190,200,150,mPaint);
            break;
            case 1:
                rectF.set(100,10,300,100);
                canvas.drawRect(rectF,mPaint);
                mPaint.setColor(Color.BLACK);
                canvas.drawOval(rectF,mPaint);
                break;
            case 2:
                mPaint.setStyle(Paint.Style.STROKE);
                rectF.set(400,100,600,300);
                canvas.drawArc(rectF,0,350,false,mPaint);
                break;
            case 3:
                 mPaint.setStyle(Paint.Style.STROKE);
                 Path path =new Path();
                 path.moveTo(10,10);
                 path.lineTo(200,68);
                 path.lineTo(300,500 );
                 path.lineTo(60,300);

             //path.close();
             canvas.drawPath(path,mPaint);
                break;
            case 4:
                Path ccRectPath=new Path();
                mPaint.setStyle(Paint.Style.STROKE);
                RectF rectF1=new RectF(50,50,240,200);
                ccRectPath.addRect(rectF1,Path.Direction.CCW);
                Path cwRectPath=new Path();
                RectF rectF2=new RectF(290,50,480,200);
                cwRectPath.addRect(rectF2,Path.Direction.CW);
                canvas.drawPath(ccRectPath,mPaint);
                canvas.drawPath(cwRectPath,mPaint);
                String text="东哥和鸡鸡今天晚上会吵架吗";
                mPaint.setColor(Color.BLACK);
                mPaint.setTextSize(35);
                canvas.drawTextOnPath(text,ccRectPath,0,18,mPaint);
                canvas.drawTextOnPath(text,cwRectPath,0,18,mPaint);
                break;

                case 5:
                    Path path1=new Path();
                    RectF rectF3=new RectF(50,50,240,200);
                    path1.addRoundRect(rectF3,10,15,Path.Direction.CCW);

                    RectF rectF4=new RectF(290,50,480,200);
                    float radii[]={10,15,20,25,30,35,60,60};
                    path1.addRoundRect(rectF4,radii,Path.Direction.CCW);
                    canvas.drawPath(path1,mPaint);
                    break;

                    case 6:

                        //String familyName="楷体";
                        String familyName="宋体";
                        Typeface font=Typeface.create(familyName,Typeface.NORMAL);
                        mPaint.setStyle(Paint.Style.STROKE);
                        mPaint.setTextSize(50);
                        mPaint.setTypeface(font);
                        // 计算Baseline绘制的起点X轴坐标 ，计算方式：画布宽度的一半 - 文字宽度的一半
                        int baseX = (int) (canvas.getWidth() / 2 - mPaint.measureText("Single-妍") / 2);

                        // 计算Baseline绘制的Y坐标 ，计算方式：画布高度的一半 - 文字总高度的一半
                        int baseY = (int) ((canvas.getHeight() / 2) - ((mPaint.descent() + mPaint.ascent()) / 2));

                        // 居中画一个文字
                        canvas.drawText("Single-妍", baseX, baseY, mPaint);

                       // canvas.drawText("Single-妍",10,100,mPaint);
                        break;



        }

    }
}
